package jdo.crud;

import java.io.IOException;
import java.io.PrintWriter;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jdo.entity.Tramway;
import jdo.pmf.PMF;
import java.util.List;
import javax.jdo.Query;



@SuppressWarnings("serial")
public class DeleteAllTramway extends HttpServlet {
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html");
		
		PersistenceManager pm = PMF.getPersistenceManager();
		Query query = pm.newQuery(Tramway.class);
		PrintWriter page = response.getWriter();
		    
		
		    try {
		    	   @SuppressWarnings("unchecked")
				List<Tramway> results = (List<Tramway>)query.execute();
		    	   
		        if (!results.isEmpty()) {
		        	
		            for (Tramway e : results) {

		            	if (e != null) {
		        			pm.deletePersistent(e);
		        			}
		            }
		        } else {
		        	page.print("La Base est deja vide");
		        }
		    } finally {
		    	//Fermetures
		        query.closeAll();}
		    	pm.close();
		
		    	page.print("<a href=/administration.jsp>Back to menu</a></body>");
		

		}
	}